import java.util.*;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }

    public ArrayList<Integer> GetLeastNumbers_Solution (int[] input, int k) {
        Queue<Integer> heap = new PriorityQueue<>();
        int n = input.length;
        for (int i = 0; i < n; i++) {
            heap.offer(input[i]);
        }
        ArrayList<Integer> result = new ArrayList<>();
        for (int i = 0; i < k; i++) {
            result.add(heap.remove());
        }
        return result;
    }

    public void moveZeroes(int[] nums) {
        int left = 0, right = 0;
        int n = nums.length;
        while (right < n&&left < n) {
            if (nums[right] != 0) {
                swap(nums,left,right);
                left++;
            }
            right++;
        }
    }
    public void swap(int[] nums,int left,int right) {
        int a = nums[left];
        nums[left] = nums[right];
        nums[right] = a;
    }

    public List<Integer> findSubstring(String ss, String[] tt) {
        List<Integer> ret=new ArrayList<>();
        Map<String,Integer> hash1=new HashMap<>();
        int n=tt.length,m=tt[0].length();
        for(String t:tt){
            hash1.put(t,hash1.getOrDefault(t,0)+1);
        }
        for(int i=0;i<m;i++){
            Map<String,Integer> hash2=new HashMap<>();
            for(int left=i,right=i,count=0;right+m<=ss.length();right+=m){
                String in=ss.substring(right,right+m);
                hash2.put(in,hash2.getOrDefault(in,0)+1);
                if(hash2.get(in)<=hash1.getOrDefault(in,0)) count++;
                if(right-left+1>m*n){
                    String out=ss.substring(left,left+m);
                    if(hash2.get(out)<=hash1.getOrDefault(out,0)) count--;
                    hash2.put(out,hash2.get(out)-1);
                    left+=m;
                }
                if(count==n) ret.add(left);
            }
        }
        return ret;
    }
    public ListNode deleteDuplicates(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode newHead = new ListNode(0,head);
        ListNode cur = newHead;
        while(cur.next != null&&cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                int x = cur.next.val;
                while(cur.next != null&&cur.next.val == x) {
                    cur.next = cur.next.next;
                }
            }
            else {
                cur = cur.next;
            }
        }
        return newHead.next;
    }
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] nums3=new int[nums1.length+nums2.length];
        int k=0,i=0,j=0;
        while(i<nums1.length&&j<nums2.length){
            if(nums1[i]>nums2[j]){
                nums3[k++]=nums2[j++];
            }
            else{
                nums3[k++]=nums1[i++];
            }
        }
        if(i>=nums1.length){
            while(j<nums2.length){
                nums3[k++]=nums2[j++];
            }
        }
        if(j>=nums2.length){
            while(i<nums1.length){
                nums3[k++]=nums1[i++];
            }
        }
        if(nums3.length%2!=0){
            return (double)nums3[nums3.length/2];
        }
        double mid=(nums3[nums3.length/2]+nums3[nums3.length/2-1])/2.0;
        return mid;
    }
}
class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

class LRUCache {
    class DLinkedNode {
        int key;
        int value;
        DLinkedNode prev;
        DLinkedNode next;
        public DLinkedNode() {}
        public DLinkedNode(int _key, int _value) {key = _key; value = _value;}
    }

    private Map<Integer, DLinkedNode> cache = new HashMap<Integer, DLinkedNode>();
    private int size;
    private int capacity;
    private DLinkedNode head, tail;

    public LRUCache(int capacity) {
        this.size = 0;
        this.capacity = capacity;
        // 使用伪头部和伪尾部节点
        head = new DLinkedNode();
        tail = new DLinkedNode();
        head.next = tail;
        tail.prev = head;
    }

    public int get(int key) {
        DLinkedNode node = cache.get(key);
        if (node == null) {
            return -1;
        }
        // 如果 key 存在，先通过哈希表定位，再移到头部
        moveToHead(node);
        return node.value;
    }

    public void put(int key, int value) {
        DLinkedNode node = cache.get(key);
        if (node == null) {
            // 如果 key 不存在，创建一个新的节点
            DLinkedNode newNode = new DLinkedNode(key, value);
            // 添加进哈希表
            cache.put(key, newNode);
            // 添加至双向链表的头部
            addToHead(newNode);
            ++size;
            if (size > capacity) {
                // 如果超出容量，删除双向链表的尾部节点
                DLinkedNode tail = removeTail();
                // 删除哈希表中对应的项
                cache.remove(tail.key);
                --size;
            }
        }
        else {
            // 如果 key 存在，先通过哈希表定位，再修改 value，并移到头部
            node.value = value;
            moveToHead(node);
        }
    }

    private void addToHead(DLinkedNode node) {
        node.prev = head;
        node.next = head.next;
        head.next.prev = node;
        head.next = node;
    }

    private void removeNode(DLinkedNode node) {
        node.prev.next = node.next;
        node.next.prev = node.prev;
    }

    private void moveToHead(DLinkedNode node) {
        removeNode(node);
        addToHead(node);
    }

    private DLinkedNode removeTail() {
        DLinkedNode res = tail.prev;
        removeNode(res);
        return res;
    }
}